<?php
declare (strict_types = 1);

namespace app\service;

use app\model\AccountCategoryModel;

class AccountCategoryService extends \think\Service
{


    /**
     * 查询列表
     *
     * @return \think\Response
     */
    public function getList($data)
    {
        $query = AccountCategoryModel::where("is_delete",1);
        if(!empty($data['cate_id'])){
            $query->where("cate_id",$data['cate_id']);
        }
        if(!empty($data['cate_name'])){
            $query->whereLike("cate_name",$data['cate_name']);
        }
        $list = $query->select();
        return $list;
    }

    /**
     * 添加分类
     */
    public function create($data)
    {
        $res = AccountCategoryModel::create($data);
        return $res;
    }

    /**
     * 修改分类
     * @param $data
     */
    public function update($data)
    {
        $res = AccountCategoryModel::where('cate_id', $data['cate_id'])->update($data);
        return $res;
    }

    /**
     * 获取分类
     */
    public function getOne($data)
    {
        $query = AccountCategoryModel::where('is_delete', 1);
        if(!empty($data['cate_id'])){
            $query->where("cate_id", $data['cate_id']);
        }
        if(!empty($data['cate_name'])){
            $query->whereLike("cate_name",$data['cate_name']);
        }
        $res = $query->find();
        return $res;
    }
    /**
     * 伪删除分类
     */
    public function delete($data)
    {
        $res = AccountCategoryModel::where('cate_id', $data['cate_id'])->update(['is_delete'=>2]);
        return $res;
    }
}
